<template>
    <div id="drugmanagement">
        <h1>药品详情</h1>
        <div class="head">
            <el-upload
            class="avatar-uploader"
            action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <!-- <i v-else class="el-icon-plus avatar-uploader-icon"></i> -->
            <div><i class="el-icon-plus"></i><em>照片</em></div>          
            </el-upload>
        </div> 
        <div class="form">
            <el-form ref="form" :model="form" label-width="80px" :label-position="left">
                <el-form-item label="药品名称:">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="药品主治:">
                    <el-input v-model="form.age"></el-input>
                </el-form-item>
                <el-form-item label="药品禁忌:">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="药品规格:">
                    <el-input v-model="form.tel"></el-input>
                </el-form-item>
                
                
            </el-form>
        </div>
        
    </div>
</template>

<script>
import { Message } from 'element-ui';

  export default {
    data() {
      return {
        imageUrl: '',
        left: 'left',
        form: {
            name: '',
            age: '',
            gender: '',
            tel: '',
            Character: ''
        }        
      };
    },
    methods: {
      handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
      onSubmit() {
        console.log('submit!');
        confirm("创建成功")
      }
    }
  }
</script> 

<style lang="less">
#drugmanagement{
    h1 {
        margin-top: 40px;
        margin-left: 30px;
    }
    .head {
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
        .avatar-uploader .el-upload--text {
            font-size: 20px;
            color: #8c939d;
            width: 350px;
            height: 178px;
            line-height: 178px;
            text-align: center;
            background-color: #fff;
        }
        margin-left: 175px;
        margin-top: 40px;
    }
    .form {
        margin-left: 95px;
        margin-top: 22px;
        width: 430px;
        .el-button--primary {
            width: 90px;
            margin-right: 30px;
        }

    }
}
   
</style>